package Dao;

import Model.Student;
import UserView.UserUi;
import fanshe6.JdbcTools;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.*;

public class DaoStuHandle {
    public void showStuDAO() throws Exception {
        String sql="select * from student";
        List<Object[]> objects = JdbcTools.queryArray1("select * from student");
        for (int i = 0; i < objects.size(); i++) {
            System.out.println(Arrays.toString(objects.get(i)));
        }
    }


    public void addStuDAO(String name,String sex,Integer age,String major,String format) throws Exception {
        String sql="insert into student values (default ,?,?,?,?,?)";
        JdbcTools.add("insert into student values (default ,?,?,?,?,?)",name,sex,age,major,format);
    }

    public boolean delStuDAO( int stuId) throws Exception {
        int delete1 = JdbcTools.delete("delete from student where id=?", stuId);
        if(delete1>0){
            return true;
        }else{
            return false;
        }
    }
    public void updateStuDAO(int stuId1) throws Exception {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你修改的姓名");
        String name = scanner.nextLine();

        System.out.println("请输入你修改的性别");
        String sex = scanner.nextLine();
        System.out.println("请输入你修改的年龄");
        int age = scanner.nextInt();
        System.out.println("请输入你修改的专业");
        String major = scanner.nextLine();
        JdbcTools.update("update student set name=?,sex=?,age=?,major=? where id=?",name,sex,age,major,stuId1);
    }
    public void searchStuDAO(Student[] stus, Integer len, Integer a) {
        System.out.println("所查找的学生信息是： " + stus[a]);
    }
    }